(function(Vue) {
    Vue.component("home", {
        template: `<h1>主页</h1>`,
    })
    Vue.component("product", {
        template: `<h1>产品详情</h1>`,
    })
    Vue.component("profile", {
        template: `<h1>公司介绍</h1>`,
    })
    let routes = [{
            path: "/home",
            component: "home"
        }, {
            path: "/product",
            component: "product"
        }, {
            path: "/profile",
            component: "profile"
        }]
        //添加hashchange监听事件
    window.addEventListener("hashchange", function(e) {
        console.log(e);
        console.log(window.location.hash);
        let path = window.location.hash.split("#")[1];
        let route_item = routes.find(v => {
            if (v.path === path) {
                return true;
            }
        })
        console.log(vm.componentId);
        vm.componentId = route_item.component;
    })
})(Vue);